

import java.util.*;

public class Car {
	
	private double posX;
        private double posY;
        private double angle;
        
	private double vitesse;
	private boolean demarre;
	
 	public Car (double vitesse, double pPosX, double pPosY, double pAngle){
            
            TimerVoiture timerVoiture = new TimerVoiture(this);
            Timer timer = new Timer();
            timer.schedule(timerVoiture, new Date(), 20);
            
            
            this.posX = pPosX;
            this.posY = pPosY;
            this.angle = pAngle; 
            this.vitesse = vitesse;
            this.demarre = false;
	}
        
        public void avancer()
        {
            
            this.vitesse*= 0.98;
            
            if (vitesse > -0.5 && vitesse < 0.5) vitesse = 0;
            
            if (this.posX > MainWin.LARGEUR)
            {
                this.posX = MainWin.LARGEUR;
                this.vitesse = 0;
            }
            else if (this.posX < 0)
            {
                this.posX = 0;
                this.vitesse = 0;
            }
            else if (this.posY > MainWin.HAUTEUR)
            {
                this.posY = MainWin.HAUTEUR;
                this.vitesse = 0;
            }
            else if (this.posY < 0)
            {
                this.posY = 0;
                this.vitesse = 0;
            }
            else // Tout est bon
            {
                double coeff = this.vitesse/10; 
                this.posX += Math.cos(angle) * coeff;
                this.posY -= Math.sin(angle) * coeff;
            }
     
        }
	
	public double getPositionX(){
		return this.posX;
	}
	
        public double getPositionY(){
		return this.posY;
	}
        
        public double getAngle(){            
                return angle;
        }
        
	public double getVitesse() {
		return this.vitesse;
	}
	
	public void demarrer() {
		this.demarre = true;
	}
	
	public void arreter() {
		this.vitesse = 0;
		this.demarre = false;
	}
	
	public boolean getStatus() {
		return this.demarre;
	}
	
	public void accelerer(double v){
		if(this.vitesse+v>200){
			this.vitesse=200;
		}else{
			this.vitesse+=v;
		}
	}
        
        public void tournerGauche(){
            
             angle += Math.PI/32;
        }

        public void tournerDroite(){
            
             angle -= Math.PI/32;
        }
        
	public void top() {
		this.posX+=this.vitesse/100;
	}
	
	public void ralentir(double v){
		if(this.vitesse-v<(-20)){
			this.vitesse=-20;
		}else{
			this.vitesse-=v;
		}
	}
	
	
}
